public class Jump {
    public static void main(String[] args) {
        int[] num = new int[]{3,2,1,0,4};
        System.out.println(canJump(num));
    }
    public static boolean canJump(int[] nums) {
        //数组能跳到的最大下标
        int maxLength = 0;
        for (int i = 0; i < nums.length; i++) {
            //遍历维护最大高度
            if(i+nums[i] >= maxLength) {
                maxLength = i+nums[i];
            }
            //最大到达点是0时，无法向后跳，直接结束循环
            if(i == maxLength) {
                break;
            }
        }
        //最大高度等于或大于数组最大下标，返回true
        if(maxLength >= nums.length-1) {
            return true;
        }else {
            return false;
        }
    }
}
